package com.dodoke.controller;

import java.util.List;

import com.dodoke.domain.WxGoodsAttr;
import com.dodoke.service.IWxGoodsAttrService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.dodoke.common.annotation.Log;
import com.dodoke.common.core.controller.BaseController;
import com.dodoke.common.core.domain.AjaxResult;
import com.dodoke.common.enums.BusinessType;
import com.dodoke.common.utils.poi.ExcelUtil;
import com.dodoke.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author dodoke
 * @date 2020-08-25
 */
@RestController
@RequestMapping("/attr")
public class WxGoodsAttrController extends BaseController
{
    @Autowired
    private IWxGoodsAttrService wxGoodsAttrService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:attr:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxGoodsAttr wxGoodsAttr)
    {
        startPage();
        List<WxGoodsAttr> list = wxGoodsAttrService.selectWxGoodsAttrList(wxGoodsAttr);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:attr:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WxGoodsAttr wxGoodsAttr)
    {
        List<WxGoodsAttr> list = wxGoodsAttrService.selectWxGoodsAttrList(wxGoodsAttr);
        ExcelUtil<WxGoodsAttr> util = new ExcelUtil<WxGoodsAttr>(WxGoodsAttr.class);
        return util.exportExcel(list, "attr");
    }

    /**
     * 通过商品id查询商品参数
     * 获取【商品参数】
     */
    @GetMapping(value = "/getGoodsAttrByGoodsId/{id}")
    public AjaxResult getGoodsAttrByGoodsId(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wxGoodsAttrService.getGoodsAttrByGoodsId(id));
    }

    /**
     * 新增【商品属性】
     */
    @PostMapping("/addGoodsAttr")
    public AjaxResult add(@RequestBody List<WxGoodsAttr> wxGoodsAttrList)
    {
        return toAjax(wxGoodsAttrService.insertWxGoodsAttr(wxGoodsAttrList));
    }

    /**
     * 修改【商品参数】
     */
    @PutMapping("/editGoodsAttr")
    public AjaxResult editGoodsAttr(@RequestBody WxGoodsAttr wxGoodsAttr)
    {
        return toAjax(wxGoodsAttrService.updateWxGoodsAttr(wxGoodsAttr));
    }

    /**
     * 删除【商品参数】
     */
    @DeleteMapping("/deleteGoodsAttr/{id}")
    public AjaxResult deleteGoodsAttr(@PathVariable Long id)
    {
        return toAjax(wxGoodsAttrService.deleteWxGoodsAttrById(id));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:attr:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wxGoodsAttrService.deleteWxGoodsAttrByIds(ids));
    }
}
